package com.xrui.hbase.util;

import java.io.IOException;

/**
 * Interface for reference-countable resources.
 *
 * @param <T> Type of the resource. Must implement ReferenceCountable.
 */
public interface ReferenceCountable<T extends ReferenceCountable<T>> {
  /**
   * Expresses interest in retaining this resource.
   *
   * The resource will not be disposed until a call to release() happens
   *
   * @return the retained resource.
   */
  T retain();

  /**
   * Notifies this resource that we are no longer interested in it.
   *
   * This resource may be disposed if no other entity has expressed interest in using it.
   *
   * @throws IOException on I/O error.
   */
  void release() throws IOException;
}
